varying vec4 diffuse,ambient;
varying vec3 normal, viewerVec;
uniform int index;
uniform vec3 lpos[500];	
//uniform vec3 lpos[500];	
	
void main()
{
	vec3 n,halfV, R, vv, l;
	float NdotL,NdotHV;

	vec4 I, Ia, Id, Is;
	vec4 color = ambient;
	n = normalize(normal);
	vv = normalize( viewerVec );
	//I = ambient;
	int iterations = index;

	for( int i = 0; i < iterations; ++i )
	{

		//l = normalize(lpos);
		l = normalize(lpos[i]);
		
		NdotL = max(dot(n,l),0.0);
	
		R = 2.0 * NdotL * n - l;

		Id = diffuse * NdotL;
		Is = gl_FrontMaterial.specular * gl_LightSource[0].specular * pow( max( dot(R, vv), 0.0), gl_FrontMaterial.shininess );
		I += Id + Is;
	}

	I.r /= 34.0; I.g /= 34.0; I.b /= 34.0;
	gl_FragColor = I;
}